/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package modelo.tableModels.editors;

import vista.extra.org.freixas.jcalendar.DateEvent;
import vista.extra.org.freixas.jcalendar.DateListener;
import vista.extra.org.freixas.jcalendar.JCalendarCombo;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
import javax.swing.AbstractCellEditor;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;
import org.w3c.dom.events.EventException;

/**
 *
 * @author Felipe
 */
public class Fecha_TableCellEditor extends AbstractCellEditor implements TableCellEditor,DateListener{

    private JCalendarCombo calendario;
    private JTable tabla;
    
    public Fecha_TableCellEditor(JCalendarCombo cbxFecha) {
        cbxFecha.addDateListener(this);
        this.calendario = cbxFecha;
    }

    @Override
    public Object getCellEditorValue() {        
        return calendario.getCalendar().getTime();
    }

    @Override
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
        Date fecha = ((Date)value);
        this.tabla = table;
        calendario.setDate(fecha);
        return calendario;
    }

    @Override
    public void dateChanged(DateEvent e) {
        this.paraEdicion();
    }

    private void paraEdicion(){
        try {
            tabla.getCellEditor().stopCellEditing();
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}
